package com.adopapa.nezhacloud.ddd.domain;

import java.io.Serializable;
import java.util.List;

import org.springframework.data.domain.Page;

@SuppressWarnings("serial")
public class PageData<T> implements Serializable {

	private int pageNo;
	private int pageSize;
	private long total;
	private int pages;
	private List<T> content;

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public long getTotal() {
		return total;
	}

	public void setTotal(long total) {
		this.total = total;
	}

	public int getPages() {
		return pages;
	}

	public void setPages(int pages) {
		this.pages = pages;
	}

	public List<T> getContent() {
		return content;
	}

	public void setContent(List<T> content) {
		this.content = content;
	}

	public static <T> PageData<T> fromPage(Page<T> page) {
		PageData<T> pageData = new PageData<>();
		pageData.setContent(page.getContent());
		pageData.setPageNo(page.getPageable().getPageNumber() + 1);
		pageData.setPageSize(page.getPageable().getPageSize());
		pageData.setTotal(page.getTotalElements());
		pageData.setPages(page.getTotalPages());
		
		return pageData;
	}

}
